package commons;

import java.util.List;

import org.codeandmagic.android.gauge.demo.R;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import android.widget.Toast;

class ViewHolder {
	TextView tv;
}

public class ItemAdapterSpin extends BaseAdapter {
	private Context mContext;
	private List<String> data;
	private ViewHolder holder;
	private LayoutInflater inflat;

	public ItemAdapterSpin(Context ctx, List<String> dataList) {
		mContext = ctx;
		data = dataList;
		inflat = (LayoutInflater) mContext
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return data.size() - 1;
	}

	@Override
	public Object getItem(int pos) {
		// TODO Auto-generated method stub
		return data.get(pos);
	}

	@Override
	public long getItemId(int pos) {
		// TODO Auto-generated method stub
		return pos;
	}

	@Override
	public View getView(int pos, View convertView, ViewGroup arg2) {
		// TODO Auto-generated method stub
		View v = convertView;
		if (v == null) {
			v = inflat.inflate(R.layout.list_spinner_data, null);
			holder = new ViewHolder();
			holder.tv = (TextView) v.findViewById(R.id.txtSpinData);
			v.setTag(holder);
		} else {
			holder = (ViewHolder) v.getTag();
		}

		if (pos == getCount()) {
			holder.tv.setText("");
			holder.tv.setHint(getItem(getCount()).toString());
		} else {
			holder.tv.setText(data.get(pos));
		}
		return v;
	}

}
